package com.freewater.springboot.demo.resource.autowire;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class SomeService {

    // 直接转换成Resource对象，牛！
    @Value("classpath:com/freewater/springboot/demo/resource/autowire/some.txt")
    private Resource textFile;

    public void printTextFile() throws IOException {
        final File file = textFile.getFile();
        System.out.println(Files.readAllLines(file.toPath()));
    }
}
